package com.soft.bams.server;


import javax.swing.*;
import java.awt.*;

public class ServerPanel extends JPanel {
    private ATMServer atmServer;

    private JButton startBtn = new JButton("开启服务");
    private JButton stopBtn = new JButton("关闭服务");
    private JButton godViewBtn = new JButton("上帝视角");

    public ServerPanel(ATMServer atmServer) {
        this.atmServer = atmServer;
        setLayout(null);
        initComponents();
    }

    private void initComponents() {
        startBtn.setBounds(300, 100, 200, 40);
        startBtn.addActionListener(e -> {
            atmServer.startServer();
        });
        add(startBtn);

        stopBtn.setBounds(300, 180, 200, 40);
        stopBtn.addActionListener(e -> {
            int result = JOptionPane.showConfirmDialog(this, "确定关闭服务吗？");
            if (result == JOptionPane.YES_OPTION) {
                atmServer.stopServer();
                System.exit(0);
            }
        });
        add(stopBtn);

        godViewBtn.setBounds(300, 260, 200, 40);
        godViewBtn.addActionListener(e -> {
            atmServer.showPanel("Rank");
        });
        add(godViewBtn);

        // 添加标题
        JLabel titleLabel = new JLabel("ATM服务端", JLabel.CENTER);
        titleLabel.setFont(new Font("宋体", Font.BOLD, 24));
        titleLabel.setBounds(0, 30, 800, 40);
        add(titleLabel);
    }
}